﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreEx.DynamicInvoker.Implementation
{
    public static class LinqExtensions
    {
        /// <summary>
        /// Allows an <see cref="Action{T}"/> to be applied to each element.
        /// </summary>
        /// <typeparam name="T">The type of elements in <paramref name="source"/></typeparam>
        /// <param name="source">An <see cref="IEnumerable{T}"/>.</param>
        /// <param name="action">The <see cref="Action{T}"/> to apply to each element in the <paramref name="source"/>.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> that contains the input sequence.</returns>        
        public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (T element in source) action(element);
            return source;
        }
    }
}
